<template>
  <div class="services">
    <div class="container">
      <h1>美容项目展示</h1>
      <p class="subtitle">我们提供全方位的美容服务，满足您不同的美丽需求</p>
      
      <!-- Category Filter -->
      <div class="category-filter">
        <button 
          v-for="category in categories" 
          :key="category"
          :class="['filter-btn', { active: selectedCategory === category }]"
          @click="selectedCategory = category"
        >
          {{ category }}
        </button>
      </div>
      
      <!-- Services Grid -->
      <div class="services-grid">
        <div 
          class="service-card" 
          v-for="service in filteredServices" 
          :key="service.id"
        >
          <div class="service-image">
            <img :src="service.image" :alt="service.name" />
            <div class="service-overlay">
              <span class="duration">{{ service.duration }}</span>
              <span class="price">{{ service.price }}</span>
            </div>
          </div>
          <div class="service-content">
            <h3>{{ service.name }}</h3>
            <p class="description">{{ service.description }}</p>
            <div class="service-meta">
              <span class="category-tag">{{ service.category }}</span>
              <span class="rating">⭐ {{ service.rating }}</span>
            </div>
            <button class="book-btn" @click="bookService(service)">立即预约</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Services',
  data() {
    return {
      selectedCategory: '全部',
      categories: ['全部', '面部护理', '眼部护理', '身体护理', '特色项目'],
      categoryMap: {
        '全部': null,
        '面部护理': 2,
        '眼部护理': 3,
        '身体护理': 4,
        '特色项目': 5
      },
      services: [
      ]
    }
  },
  computed: {
    filteredServices() {
      if (this.selectedCategory === '全部') {
        return this.services;
      }
      const categoryId = this.categoryMap[this.selectedCategory];
      return this.services.filter(service => service.category_id === categoryId);
    }
  },
  async mounted() {
    await this.fetchServices();
  },
  methods: {
    async fetchServices() {
      try {
        const response = await fetch('/salon/project/list', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
          })
        });
        const data = await response.json();
        // 处理POST请求返回的数据格式
        const services = data.data || data.list || data;
        this.services = services.map(service => ({
          id: service.id,
          name: service.name,
          description: service.description,
          price: `¥${service.price}`,
          image: service.imageUrl,
          category_id: service.category,
          category_name: service.category_name
        }));
      } catch (error) {
        console.error('获取服务数据失败:', error);
      }
    },
    bookService(service) {
      alert(`已选择预约: ${service.name}\n价格: ${service.price}`);
    }
  }
}
</script>

<style scoped>
.services {
  padding: 4rem 0;
  background: #f8f9fa;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

h1 {
  text-align: center;
  font-size: 2.5rem;
  color: #333;
  margin-bottom: 1rem;
}

.subtitle {
  text-align: center;
  font-size: 1.2rem;
  color: #666;
  margin-bottom: 3rem;
}

.category-filter {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 3rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.8rem 1.5rem;
  border: 2px solid #667eea;
  background: white;
  color: #667eea;
  border-radius: 25px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;
}

.filter-btn.active,
.filter-btn:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  transform: translateY(-2px);
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 2rem;
}

.service-card {
  background: white;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
}

.service-card:hover {
  transform: translateY(-5px);
}

.service-image {
  position: relative;
  height: 250px;
  overflow: hidden;
}

.service-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.service-card:hover .service-image img {
  transform: scale(1.1);
}

.service-overlay {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.duration {
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 0.3rem 0.8rem;
  border-radius: 15px;
  font-size: 0.8rem;
  font-weight: 500;
}

.price {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-weight: 600;
}

.service-content {
  padding: 1.5rem;
}

.service-content h3 {
  font-size: 1.3rem;
  color: #333;
  margin-bottom: 1rem;
}

.description {
  color: #666;
  line-height: 1.6;
  margin-bottom: 1rem;
}

.service-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.category-tag {
  background: #e3f2fd;
  color: #1976d2;
  padding: 0.3rem 0.8rem;
  border-radius: 15px;
  font-size: 0.8rem;
  font-weight: 500;
}

.rating {
  color: #ffa726;
  font-weight: 600;
}

.book-btn {
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.book-btn:hover {
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .services-grid {
    grid-template-columns: 1fr;
  }
  
  .category-filter {
    gap: 0.5rem;
  }
  
  .filter-btn {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }
  
  h1 {
    font-size: 2rem;
  }
}
</style>